home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / rexx / console.raz < prev    next >
Text File  |  1994-10-09  |  3KB  |  79 lines

  1. /** $VER: Console.raz 1.1 (5.9.94)
  2.  **
  3.  ** Console de commandes pour AZur
  4.  **
  5.  ** Inspiré de CmdShell.ttx de David N. Junod, Bill Hawes et Martin Taillefer
  6.  **
  7.  ** Version AZur : Jean-Michel Forgeas
  8.  **
  9.  ** La console accepte des commandes AZur en direct, mais qui vont passer
  10.  ** par l'intermédiaire de ARexx.
  11.  ** Il est possible de taper des commandes ARexx qui ne soient pas AZur
  12.  ** en mettant un " ou un ' en début de ligne (si il y a des " dans la commande
  13.  ** mettez un ' et inversement).
  14.  ** Par exemple pour afficher 5 fois XXX vous pouvez taper :
  15.  **     "do i=1 to 5; say XXX; end
  16.  ** Ou encore pour tester la fonction ARexx "index()" tapez :
  17.  **     'say index("aa bb cc dd ","cc")
  18.  ** qui va afficher : 7
  19.  **/
  20.  
  21.  
  22. OPTIONS RESULTS
  23. OPTIONS FAILAT 100
  24.  
  25. nl = 'a'x
  26. HelpString = '1b'x||"[1;;47;>7m"||"       »»» Console de commandes AZur «««"||nl||nl||'1b'x||"[0;32;47;>7m"||"       Quitter ==> <RETURN>"||nl"       Aide    ==> Help <nom de commande>"||nl||'1b'x||"[0m"
  27. SAY HelpString
  28.  
  29. DO FOREVER      /* Get input until the user closes the Command Shell */
  30.     /*
  31.     OPTIONS PROMPT '1b'x||"[1;35m"Time()" AZur> "||'1b'x||"[0;31m"
  32.     */
  33.     OPTIONS PROMPT '1b'x||"[1;36;47;>7m"Time()" AZur> "||'1b'x||"[0;31;47;>7m"
  34.     PARSE PULL CmdString    /* Wait until the user types a command followed by RETURN */
  35.     SELECT
  36.         WHEN (CmdString = "") THEN LEAVE
  37.         WHEN (CmdString = "?") | (UPPER(CmdString) = "HELP") THEN SAY HelpString
  38.         OTHERWISE CALL HandleCmd(CmdString)
  39.     END
  40. END
  41. EXIT
  42.  
  43. HandleCmd: PROCEDURE
  44. PARSE ARG CmdString
  45.  
  46.     ch = LEFT(CmdString,1)
  47.     IF (ch~="'" & ch~='"' & WORDS(CmdString)=2) THEN DO
  48.         IF (WORD(CmdString,2)="?") THEN CmdString = 'Help '||WORD(CmdString,1)
  49.     END
  50.  
  51.     CmdString /* Execute the command */
  52.  
  53.     IF RC = 0 THEN DO /* See if the command succeeded */
  54.         /*IF symbol('RESULT') == "VAR" THEN SAY RESULT*/
  55.         IF (length(RESULT) > 0) THEN SAY RESULT
  56.         RETURN
  57.     END
  58.  
  59.     error = AZur.LastError; IF error = "AZUR.LASTERROR" THEN error = AZurMast.LastError
  60.     errortext = AZur.LastErrorText; IF errortext = "AZUR.LASTERRORTEXT" THEN errortext = AZurMast.LastErrorText
  61.  
  62.     IF error = 24 THEN DO
  63.         /* Wasn't an editor command, try running it as an ARexx script */
  64.         ADDRESS REXX CmdString
  65.                 /* On pourrait voir si c'est une commande Shell avec la ligne
  66.                  * ci-dessous, mais j'ai jugé cela trop dangereux pour le laisser
  67.                  * par défaut : des commandes Shell pourraient avoir le même nom
  68.                  * qu'une commande non trouvée de AZur. Par exemple si on tapait
  69.                  * "Format" pour mettre le texte en forme, cela enverrait la
  70.                  * commande Shell "Format"...
  71.                  *
  72.                  * IF RC > 0 THEN ADDRESS COMMAND CmdString
  73.                  */
  74.         IF RC > 0 THEN SAY "»»» Commande passée à ARexx : erreur "RC
  75.     END
  76.     ELSE SAY '»»» Erreur 'error' : 'errortext
  77.  
  78. RETURN
  79.